package com.qwc.blog.entity.vo.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.qwc.blog.entity.User;
import lombok.Data;

import java.util.Date;

import static com.qwc.blog.security.constant.SecurityConstant.*;

/**
 * @author qwc
 * @Date 2021/10/23 17:55
 */
@Data
public class CurrentUserVo {

    /**
     * ID
     */
    private Integer userId;

    /**
     * 账号
     */
    private String username;

    /**
     * 昵称
     */
    private String nickname;

    /**
     * 头像地址
     */
    private String avatar;

    /**
     * 用户性别（0男 1女 2未知）
     */
    private String sex;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 手机号码
     */
    private String phoneNumber;

    /**
     * 角色
     */
    private String role;

    /**
     * 简介
     */
    private String introduction;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public static CurrentUserVo createVo(User user) {
        CurrentUserVo dto = new CurrentUserVo();
        dto.setUserId(user.getUserId());
        dto.setUsername(user.getUsername());
        dto.setAvatar(user.getAvatar());
        dto.setEmail(user.getEmail());
        dto.setNickname(user.getNickname());
        dto.setPhoneNumber(user.getPhoneNumber());
        dto.setSex(user.getSex());
        dto.setCreateTime(user.getCreateTime());
        dto.setRole(ADMIN_CODE.equals(user.getStatus()) ? ADMIN : ORDINARY);
        dto.setIntroduction(user.getIntroduction());
        return dto;
    }
}
